from flask import jsonify, request
from Modules.sys_module.model import ActionModel


def reg_interface(app=None):
    @app.route('/api/interface', methods=['GET'])
    def interface():
        result = {
            "code": "0x00010",
            "msg": "",
            "data": {
                "url": "",
                "method": ""
            }
        }
        api_mark = request.args.get('apiMark')
        data_ins = ActionModel.query.filter_by(mark=api_mark).first()
        if data_ins is None:
            result['code'] = '0x00011'
            result['msg'] = '没有接口'
            return jsonify(result)
        result["data"] = {
            "url": data_ins.api,
            "method": data_ins.method,
        }
        if data_ins.scope is not None:
            result['data']['scope'] = data_ins.scope
        return jsonify(result)
